# 多协议封装练习
import requests
import xmltodict
from requests import Response


def reponse_to_dict(response: Response):
    res = response.text
    if res.startswith("<?xml"):
        res_dict = xmltodict.parse(res)
    else:
        res_dict = response.json()
    return res_dict


class TestDemo:

    def setup_class(self):
        pass

    def test_demo1(self):
        res = requests.get("https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss")
        res_dict = reponse_to_dict(res)
        assert isinstance(res_dict, dict)

    def test_demo2(self):
        res = requests.get("https://httpbin.testing-studio.com/get")
        res_dict = reponse_to_dict(res)
        assert isinstance(res_dict, dict)
